var mask = null;
var count = 1
var login_user = null
var search = null
var stu_id = null;
$(function() { // 初始化内容

	mask = mui.createMask(); //遮罩层
	login_user = JSON.parse(localStorage.getItem('loginUser'));
	stu_id = sessionStorage.getItem('stu_id')
	mui.init();
	tap_init();
	mui('#pullrefresh').pullRefresh({

		up: { //上拉加载
			height: 50, //可选.默认50.触发上拉加载拖动距离
			auto: true, //可选,默认false.自动上拉加载一次
			contentrefresh: "正在加载...",
			contentnomore: '没有更多数据了',
			callback: function() { //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
				window.setTimeout(function() {
					pullupRefresh()
				}, 500);
			}
		}

	})

	// if(stu_id != null && stu_id != "" && stu_id != undefined){
	// 	pullupRefresh();
	// }
	datetime_init();


})




function pullupRefresh() {
	if (stu_id != null && stu_id != "" && stu_id != undefined) {
		loadContract()
	}
}



var app = new Vue({
	el: '#app',
	data: {
		show: true,
		todos: []
	},
	methods: {

	}
});



function tap_init() {


	mui(".mui-scroll").on("tap", ".mui-control-item", function(e) {
		var id = this.getAttribute("data_id");
		console.log(id)

		console.log("跳转")
		window.sessionStorage.setItem("contract_id", id)
		window.location.href = "look_contract.html"
	});


}


function recover(){
	search = null;
	count = 1;
	pullupRefresh();
}


function loadContract() {
	var data = {};

	data['page'] = count;
	data["rows"] = 20;
	data["stuid"] = stu_id;
	console.log("合同列表上传=====" + JSON.stringify(data));
	jQuery.ajax({
		type: "post",
		headers: {
			'Authorization': login_user.token
		},
		url: serverip + "fxgw/pxxyGrid",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {

			mask.show(); //显示遮罩层	
		},
		success: function(res) {
			count++
			mask.close(); //显示遮罩层 	  
			console.log("记录列表" + JSON.stringify(res));
			if(res.contractList.length>0){
			
				for (var i = 0; i < res.contractList.length; i++) {
			
					app.todos.push(res.contractList[i])
				}
			}else{
				mui.alert('没有更多数据了');
			}
			

			//数据加载完成后执行的操作,隐藏加载页面,显示数据
			mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //停止正在加载
			mui('#pullrefresh').pullRefresh().enablePullupToRefresh(true); //启用上拉加载
		},
		error: function(e) {

			mask.close(); //显示遮罩层
			mui.alert('系统错误');
			console.log("错误信息====" + JSON.stringify(e));
		}
	});
}
